//
// Calc.cpp for 210 in /home/druart_p/Work/math/my-math-epi/210
//
// Made by pierrick druart
// Login   <druart_p@epitech.net>
//
// Started on  Mon May 28 11:28:04 2012 pierrick druart
// Last update Fri Jun  1 09:57:44 2012 pierrick druart
//

#include	"Calc.hh"

// Construtor & Destructor

Calc::Calc()
{
  this->_xcar = 0;
}

Calc::~Calc() {}

void		Calc::start()
{
  int		nb = 0;

  srand(time(NULL));
  init();
  for (int i = 0; i < 1000; i++)
    {
      nb = rand() % 10;
      this->_value[nb]++;
    }
  print();
  Xcar();
  fourchette();
}

void		Calc::init()
{
  for (int i = 0; i < 10; i++)
    this->_value.push_back(0);
}

void		Calc::print()
{
  std::cout << std::endl << "\tx\t|\tOx" << std::endl;
  std::cout << "\t\t|\t" << std::endl;
  for (int j = 0; j < 10; j++)
    std::cout << "\t" << j << "\t|\t"<< this->_value[j] << std::endl;
}

void		Calc::Xcar()
{

  for (int j = 0; j < 10; j++)
    this->_xcar += pow((this->_value[j] - 100), 2) / 100;
  std::cout << std::endl<< "X2 = " << this->_xcar << std::endl << std::endl;
}

void		Calc::fourchette()
{
  if (this->_xcar <= 0)
    std::cout << "X2 = 0" << std::endl << "P = 100%" << std::endl;
  else if (this->_xcar > 0 && this->_xcar <= 4.168)
    std::cout << "0 < X2 <= 4.168" << std::endl << "100% > P >= 90%" << std::endl;
  else if (this->_xcar > 4.168 && this->_xcar <= 5.380)
    std::cout << "4.168 < X2 <= 5.380" << std::endl << "90% > P >= 80%" << std::endl;
  else if (this->_xcar > 5.380 && this->_xcar <= 6.393)
    std::cout << "5.380 < X2 <= 6.393" << std::endl << "80% > P >= 70%" << std::endl;
  else if (this->_xcar > 6.393 && this->_xcar <= 8.343)
    std::cout << "6.393 < X2 <= 8.343" << std::endl << "70% > P >= 50%" << std::endl;
  else if (this->_xcar > 8.343 && this->_xcar <= 10.656)
    std::cout << "8.343 < X2 <= 10.656" << std::endl << "50% > P >= 30%" << std::endl;
  else if (this->_xcar > 10.656 && this->_xcar <= 12.242)
    std::cout << "10.656 < X2 <= 12.242" << std::endl << "30% > P >= 20%" << std::endl;
  else if (this->_xcar > 12.242 && this->_xcar <= 14.684)
    std::cout << "12.242 < X2 <= 14.684" << std::endl << "20% > P >= 10%" << std::endl;
  else if (this->_xcar > 14.684 && this->_xcar <= 16.919)
    std::cout << "14.684 < X2 <= 16.919" << std::endl << "10% > P >= 5%" << std::endl;
  else if (this->_xcar > 16.919 && this->_xcar <= 19.679)
    std::cout << "16.919 < X2 <= 19.679" << std::endl << "5% > P >= 2%" << std::endl;
  else if (this->_xcar > 19.679 && this->_xcar <= 21.666)
    std::cout << "19.679 < X2 <= 21.666" << std::endl << "2% > P >= 1%" << std::endl;
  else
    std::cout << "21.666 < X2 <= 1000" << std::endl << "1% > P >= 0%" << std::endl;
}
